package com.demo.service.serviceImpl;

import com.demo.common.Pager;
import com.demo.common.StringUtil;
import com.demo.dao.SysManagersLoginInfoDao;
import com.demo.model.SysManagersLoginInfo;
import com.demo.model.TabUsers;
import com.demo.service.SysManagersLoginInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class SysManagersLoginInfoServiceImpl implements SysManagersLoginInfoService {

    @Resource
    private SysManagersLoginInfoDao dao;

    @Override
    public int total_login() {
        return dao.total_login();
    }

    @Override
    public void searchpages(SysManagersLoginInfo info, HttpServletRequest request) {
        String url="sys_managers_login_info_view?loginname="+info.getLoginname();
        int size=20;
        if(StringUtil.isNotEmpty(info.getLoginname()))
            info.setLoginname("%"+info.getLoginname()+"%");

        int rows=dao.countByExampleSearch(info);
        int cpage= request.getParameter("pager") == null ? 1 : Integer
                .parseInt(request.getParameter("pager"));
        if(cpage==0) {
            cpage=1;
        }
        String pager= Pager.getPagerStr(url, size, rows, cpage, 1);
        request.setAttribute("pager", pager);
        SysManagersLoginInfo query=new SysManagersLoginInfo(info.getLoginname(),size*(cpage-1),size,"id","desc");
        List<SysManagersLoginInfo> list=dao.searchByPage(query);
        request.setAttribute("rows",rows);
        request.setAttribute("list", list);
    }

    @Override
    public void save(SysManagersLoginInfo info) {
        dao.save(info);
    }

    @Override
    public void del(String id) {
        dao.del(id);
    }
}
